package com.clear.subject.application.controller;

import com.clear.subject.common.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/subject/mq")
@Slf4j
public class TestMqController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 测试发送mq消息
     *
     * @param id
     */
    @PostMapping("/pushMessage")
    public Result<Boolean> pushMessage(@RequestParam("id") int id) {
        // 队列名称
        String queueName = "simple.queue";
        // 发送
        rabbitTemplate.convertAndSend(queueName, id + "");
        return Result.ok();
    }
}
